package com.tledu.controller;

import com.sun.org.apache.xpath.internal.objects.XString;
import com.tledu.model.AjaxResult;
import com.tledu.model.Department;
import com.tledu.model.User;
import com.tledu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//实例化
@Controller
//执行Mapper
@RequestMapping("/user")
public class UserController {
    //自动装配
    @Autowired
    //将IUserService注入进来
    private IUserService userService;

    @RequestMapping("/login")
    //因为要以json格式返回, 所以使用ResponseBody
    @ResponseBody
    //在AjaxResult中封装一个Boolean类型,并添加set,get,等方法
    public AjaxResult login(User user, HttpSession session){
        //这句话最终会调用SQL语句(校验用户名和密码是否相同)
        User u  = userService.checkLogin(user);
        if(u!=null){
            session.setAttribute("loginUser",u);
            return new AjaxResult(null,null,true,null);
        }else{
            return new AjaxResult(null,null,false,null);
        }
    }
    //登陆成功后跳转到首页
    @RequestMapping("/shouye")
    public String shouye(){
        return "shouye";
    }

}